//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.goldhuman.IO.Protocol;

import com.goldhuman.Common.Marshal.OctetsStream;

import java.util.Iterator;
import java.util.Vector;

public final class ProtocolBinder extends com.goldhuman.IO.Protocol.Protocol {
    private Vector binder = new Vector();

    public ProtocolBinder() {
    }

    public OctetsStream marshal(OctetsStream os) {
        synchronized(this.binder) {
            Iterator it = this.binder.iterator();

            while(it.hasNext()) {
                ((com.goldhuman.IO.Protocol.Protocol)it.next()).Encode(os);
            }

            return os;
        }
    }

    public OctetsStream unmarshal(OctetsStream os) {
        com.goldhuman.IO.Protocol.Stream is = (Stream)os;
        synchronized(this.binder) {
            try {
                com.goldhuman.IO.Protocol.Protocol protocol;
                while((protocol = com.goldhuman.IO.Protocol.Protocol.Decode(is)) != null) {
                    this.binder.add(protocol);
                }

                Iterator it = this.binder.iterator();

                while(it.hasNext()) {
                    Task.Dispatch(is.session.manager, is.session, (com.goldhuman.IO.Protocol.Protocol)it.next());
                }
            } catch (Exception var5) {
                is.session.Close();
            }

            return os;
        }
    }

    public Object clone() {
        try {
            ProtocolBinder o = (ProtocolBinder)super.clone();
            synchronized(this.binder) {
                Iterator it = this.binder.iterator();

                while(it.hasNext()) {
                    o.binder.add(((com.goldhuman.IO.Protocol.Protocol)it.next()).clone());
                }

                return o;
            }
        } catch (Exception var5) {
            return null;
        }
    }

    public void Process(Manager manager, Session session) throws ProtocolException {
    }

    ProtocolBinder bind(Protocol protocol) {
        synchronized(this.binder) {
            this.binder.add(protocol);
            return this;
        }
    }
}
